$(function() {
	app = new Vue({
		el : '#app',
		data : {
			discount : {}
		},
		methods : {
			closeWin:function(){
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		},
		 resetForm:function(){
			$('#discount-form')[0].reset();
		},

		 getDiscountId:function(){
			var addr = location.href;
			var index = addr.lastIndexOf('/') + 1;
			var id = addr.substr(index);
			return id;
		},

		 getDiscount:function(){
			var id = this.getDiscountId();
			$.ajax({
			    type: "GET",
			    url: '/manager/discount/get/'+id,
			    beforeSend: function () {
			    },
			    complete: function () {
			    },
			    error: function(request) {
			        alert("Connection error");
			    },
			    success: function(result) {
			        if (result.status == 0) {
			        	var data = result.data;
			        	app.discount = data;
			        }
			    }
			});
		},

		init:function(){
			this.getDiscount();
			$("#discount-form").validate({
				rules:{
					discountIntegral : {
						required : true
					},
					limitIntegral : {
						required : true
					},
					daybegin : {
						required : true
					},
					status : {
						required : true
					},
					dayend: {
						required : true
					}
				},
				onkeyup:false,
				focusCleanup:true,
				success:"valid",
				submitHandler:function(form){
					var data = $('#discount-form').serialize();
					$.ajax({
					    type: "POST",
					    url: '/manager/discount/update',
					    data: data,
					    beforeSend: function () {
					    	
					    },
					    complete: function () {
					    	
					    },
					    error: function(request) {
					    	layer.alert("系统出错");
					    },
					    success: function(data) {
					    	if (data.status == 0) {
					    		refreshParentList();
								layer.alert(data.message, function() {
									var index = parent.layer.getFrameIndex(window.name);
									parent.layer.close(index);
								});
							}else{
								layer.alert(data.message);
							}
					    }
					});
				}
			});
		}}
	});
	
	app.init();
});